package cn.mado.org.controller;

import cn.mado.org.domain.User;
import cn.mado.org.dto.LoginDto;
import cn.mado.org.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping()
    public User login(@RequestBody LoginDto loginDto, HttpServletRequest request) {
        User user = userService.login(loginDto);
        request.getSession().setAttribute("user",user);
        return user;
    }


}
